package com.share.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
一、ServletConfig.java  可以获取配置文件的信息（仅限于当前的<servlet>），主要是可以获取ServletContext.java

二、获取ServletConfig.java 的方式
    1、从GenericServlet.java的init(ServletConfig config)中获取
    2、从Servlet.java的getServletConfig() 中获取
    3、因为GenericServlet.java impl ServletConfig.java，所以可以直接用ServletConfig.java中的方法
 */
public class ServletConfig1 extends HttpServlet {

//    public ServletConfig config;
//
//    @Override
//    public void init(ServletConfig config) throws ServletException {
//        this.config = config;
//    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //方式一
//        String name = config.getInitParameter("name");
        //方式二
//        ServletConfig sc = getServletConfig();
//        String name = sc.getInitParameter("name");
        //方式三
        String name = getInitParameter("name");
        System.out.println("name:" + name);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
